require([ /* 'post', */ 'jquery', 'ods'], function( /* p, */ $, ods) {
	//对栈的运用  十进制转换成任何进制
	function baseConverter(decNumber, base) {
		var remStack = new ods.Stack(),
			rem,
			baseString = '',
			digits = '0123456789ABCDEF'; //{6} 
		while (decNumber > 0) {
			rem = Math.floor(decNumber % base);
			remStack.push(rem);
			decNumber = Math.floor(decNumber / base);
		}
		while (!remStack.isEmpty()) {
			baseString += digits[remStack.pop()]; //{7} 
		}
		return baseString;
	};
	console.log(baseConverter(10, 16));

	var pq = new ods.PriorityQueue();
	pq.enqueue("John", 2);
	pq.enqueue("Jack", 1);
	pq.enqueue("Camila", 1);
	pq.print();

	//击鼓传花游戏模拟
	function hotPotato(nameList, num) {
		var queue = new ods.Queue(); // {1} 
		for (var i = 0; i < nameList.length; i++) {
			queue.enqueue(nameList[i]); // {2} 
		}
		var eliminated = '';
		while (queue.size() > 1) {
			for (var i = 0; i < num; i++) {
				queue.enqueue(queue.dequeue()); // {3} 
			}
			eliminated = queue.dequeue(); // {4} 
			console.log(eliminated + '在击鼓传花游戏中被淘汰。');
		}
		return queue.dequeue(); // {5} 
	}
	var names = ['John', 'Jack', 'Camila', 'Ingrid', 'Carl'];
	var winner = hotPotato(names, 3);
	console.log('胜利者：' + winner);

	var list = new ods.LinkedList();
	list.append("a");
	list.append("b");
	list.append("c");
	list.insert(1, "d");
	console.log(list.toString());

	var set = new ods.Set();
	set.add(1);
	console.log(set.values()); //输出["1"] 
	console.log(set.has(1)); //输出true 
	console.log(set.size()); //输出1 
	set.add(2);
	console.log(set.values()); //输出["1", "2"] 
	console.log(set.has(2)); //true 
	console.log(set.size()); //2 
	set.remove(1);
	console.log(set.values()); //输出["2"] 
	set.remove(2);
	console.log(set.values()); //输出[]

	console.log("集合操作");
	var setA = new ods.Set();
	setA.add(1);
	setA.add(2);
	setA.add(3);
	var setB = new ods.Set();
	setB.add(3);
	setB.add(4);
	setB.add(5);
	setB.add(6);
	var unionAB = setA.union(setB);
	console.log(unionAB.values());
	var intersectionAB = setA.intersection(setB);
	console.log(intersectionAB.values());
	var differenceAB = setA.difference(setB);
	console.log(differenceAB.values());
	console.log(setA.subset(setB));

	//字典
	console.log("字典");
	var dictionary = new ods.Dictionary();
	dictionary.set('Gandalf', 'gandalf@email.com');
	dictionary.set('John', 'johnsnow@email.com');
	dictionary.set('Tyrion', 'tyrion@email.com');
	console.log(dictionary.has('Gandalf'));
	console.log(dictionary.size());
	console.log(dictionary.keys());
	console.log(dictionary.values());
	console.log(dictionary.get('Tyrion'));
	dictionary.remove('John');
	console.log(dictionary.keys());
	console.log(dictionary.values());
	console.log(dictionary.getItems());

	var hash = new ods.HashTable();
	hash.put('Gandalf', 'gandalf@email.com');
	hash.put('John', 'johnsnow@email.com');
	hash.put('Tyrion', 'tyrion@email.com');
	console.log(hash.get('Gandalf'));
	console.log(hash.get('Loiane'));

	//图
	var graph = new ods.Graph();
	var myVertices = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']; //{7} 
	for (var i = 0; i < myVertices.length; i++) { //{8} 
		graph.addVertex(myVertices[i]);
	}
	graph.addEdge('A', 'B'); //{9} 
	graph.addEdge('A', 'C');
	graph.addEdge('A', 'D');
	graph.addEdge('C', 'D');
	graph.addEdge('C', 'G');
	graph.addEdge('D', 'G');
	graph.addEdge('D', 'H');
	graph.addEdge('B', 'E');
	graph.addEdge('B', 'F');
	graph.addEdge('E', 'I');
	console.log(graph.toString());

	function printNode(value) { //{16} 
		console.log('Visited vertex: ' + value); //{17} 
	}
	graph.bfs(myVertices[0], printNode); //{18}
	var shortestPathA = graph.BFS(myVertices[0]);
	console.log(shortestPathA);
	var fromVertex = myVertices[0]; //{9} 
	for (var i = 1; i < myVertices.length; i++) { //{10} 
		var toVertex = myVertices[i], //{11} 
			path = new ods.Stack(); //{12} 
		for (var v = toVertex; v !== fromVertex; v = shortestPathA.predecessors[v]) { //{13} 
			path.push(v); //{14} 
		}
		path.push(fromVertex); //{15} 
		var s = path.pop(); //{16} 
		while (!path.isEmpty()) { //{17} 
			s += ' - ' + path.pop(); //{18} 
		}
		console.log(s); //{19} 
	}

	graph.dfs(printNode);
	myVertices = ['A', 'B', 'C', 'D', 'E', 'F'];
	for (i = 0; i < myVertices.length; i++) {
		graph.addVertex(myVertices[i]);
	}
	graph.addEdge('A', 'C');
	graph.addEdge('A', 'D');
	graph.addEdge('B', 'D');
	graph.addEdge('B', 'E');
	graph.addEdge('C', 'F');
	graph.addEdge('F', 'E');
	var result = graph.DFS();
	
	// es5 dom1级
	if(n1.nodeType==1){
		console.log([n1.nodeName,n1.nodeValue,n1.childNodes,n1.hasChildNodes(),n1.ownerDocument,n1.cloneNode(true).innerHTML,document.documentElement])
	};
	console.log([document,Element,Text,Comment])
});
